<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>If var [not] in/contains value1,value2,...</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>If var [not] in/contains value1,value2,...</h1>

<p>Checks whether a <a href="../Variables.htm">variable's</a> contents match one of the items in a list.</p>

<pre class="Syntax">if <i>Var</i> in <i>MatchList</i>
if <i>Var</i> not in <i>MatchList</i>

if <i>Var</i> contains <i>MatchList</i>
if <i>Var</i> not contains <i>MatchList</i></pre>
<h3>Parameters</h3>
<dl>

  <dt>Var</dt>
  <dd><p>The name of the <a href="../Variables.htm">variable</a> whose contents will be checked. For the &quot;in&quot; operator, an exact match with one of the list items is required. For the &quot;contains&quot; operator, a match occurs more easily: whenever <em>Var</em> contains one of the list items as a substring.</p></dd>

  <dt>MatchList</dt>
  <dd><p>A comma-separated list of strings, each of which will be compared to the contents of <em>Var</em> for a  match. <strong>Any spaces or tabs around the delimiting commas are significant</strong>, meaning that they are part of the match string. For example, if <em>MatchList</em> is set to <code>ABC , XYZ</code> then <em>Var</em> must contain either ABC with a trailing space or XYZ with a leading space to cause a match.</p>
      <p>Two consecutive commas results in a single literal comma. For example, the following would produce a single literal comma at the end of string1: <code>If Var In string1,,,string2</code>. Similarly, the following list contains only a single item with a literal comma inside it: <code>If Var In single,,item</code>. To include a blank item in the list, make the first character a comma as in this example: <code>If Var In ,string1,string2</code> (when using the &quot;contains&quot; operator, a blank item will always result in a match since the empty string is found in all strings).</p>
      <p>Because the items in <em>MatchList</em> are not treated as individual parameters, the list can be contained entirely within a variable. In fact, all or part of it must be contained in a variable if its length exceeds 16383 since that is the maximum length of any script line. For example, <em>MatchList</em> might consist of <code>%List1%,%List2%,%List3%</code> -- where each of the sublists contains a large list of match phrases.</p>
      <p>Any single item in the list that is longer than 16384 characters will have those extra characters treated as a new list item. Thus, it is usually best to avoid including such items.</p></dd>

</dl>

<h3>Remarks</h3>
<p>The comparison is always done alphabetically, not numerically. For example, the string &quot;11&quot; would not match the list item &quot;11.0&quot;.</p>
<p>The &quot;contains&quot; operator is the same as using <a href="IfInString.htm">IfInString/IfNotInString</a> except that multiple search strings are supported (any one of which will cause a match).</p>
<p><code><a href="StringCaseSense.htm">StringCaseSense</a> On</code> can be used to make the comparison case sensitive.</p>
<p>If <em>MatchList</em> is long, it can be broken up into several shorter lines by means of a <a href="../Scripts.htm#continuation">continuation section</a>, which might improve readability and maintainability.</p>
<p><strong>The operators &quot;between&quot;, &quot;is&quot;, &quot;in&quot;, and &quot;contains&quot; are not supported in <a href="../Variables.htm#Expressions">expressions</a>.</strong></p>
<h3>Related</h3>
<p><a href="IfBetween.htm">if var between</a>, <a href="IfEqual.htm">IfEqual/Greater/Less</a>, <a href="IfInString.htm">IfInString</a>, <a href="StringCaseSense.htm">StringCaseSense</a>, <a href="Block.htm">Blocks</a>, <a href="Else.htm">Else</a></p>
<h3>Examples</h3>
<pre class="NoIndent">if var in exe,bat,com
    MsgBox The file extension is an executable type.

if var in 1,2,3,5,7,11 <em>; Avoid spaces in list.</em>
    MsgBox %var% is a small prime number.

if var contains 1,3  <em>; Note that it compares the values as strings, not numbers.</em>
    MsgBox Var contains the digit 1 or 3 (Var could be 1, 3, 10, 21, 23, etc.)

if var in %MyItemList%
    MsgBox %var% is in the list.

InputBox, UserInput, Enter YES or NO
if UserInput not in yes,no
    MsgBox Your input is not valid.

WinGetTitle, active_title, A
if active_title contains Address List.txt,Customer List.txt
    MsgBox One of the desired windows is active.
if active_title not contains metapad,Notepad
    MsgBox But the file is not open in either Metapad or Notepad.</pre>

</body>
</html>
